<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改产品管理')" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-manager-edit" th:object="${manager}">
        <input id="managerId" name="managerId" type="hidden" th:field="*{managerId}"/>
        <div class="form-group">
            <label class="col-sm-3 control-label">型号：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="managerNum" id="managerNum" th:field="*{managerNum}" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">品名：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="managerName" id="managerName" th:field="*{managerName}" >
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">类别：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="managerCategory" id="managerCategory" th:field="*{managerCategory}" >
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">系列：</label>
            <div class="col-sm-8">
                <select class="form-control" name="seriesId">
                    <option th:each="series:${series}" th:value="${series.seriesId}" th:selected="${manager.seriesId eq series.seriesId}">[[${series.seriesName}]]</option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">风格：</label>
            <div class="col-sm-8">
                <select class="form-control" name="styleId">
                    <option th:each="style:${style}" th:value="${style.styleId}" th:selected="${manager.styleId eq style.styleId}">[[${style.styleName}]]</option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">规格：</label>
            <div class="col-sm-8">
                <select class="form-control" name="specificationId">
                    <option th:each="specification:${specification}" th:value="${specification.specificationId}" th:selected="${manager.specificationId eq specification.specificationId}">[[${specification.specificationName}]]</option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">材质：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="managerTexture" id="managerTexture" th:field="*{managerTexture}" >
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">产地：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="managerAddress" id="managerAddress" th:field="*{managerAddress}" >
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">单价：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="managerNuitPrice" id="managerNuitPrice" th:field="*{managerNuitPrice}" >
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">数量：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="managerCount" id="managerCount" th:field="*{managerCount}" >
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">金额：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="managerTotalPrice" id="managerTotalPrice" th:field="*{managerTotalPrice}" >
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">进口家具在途：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="managerTransportation" id="managerTransportation" th:field="*{managerTransportation}" >
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">备注：</label>
            <div class="col-sm-8">
                <textarea id="managerDesc" name="managerDesc" class="form-control">[[*{managerDesc}]]</textarea>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">图片选择：</label>
            <div class="col-sm-8">
                <select class="form-control" name="urlId" onchange="imagesNodeId(this)">
                    <option th:each="url:${url}" th:value="${url.urlId}" th:selected="${url.urlId eq manager.urlId}">[[${url.urlId}]]</option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">图片：</label>
            <div class="col-sm-8">
                <img id="urlSrcId" th:src="*{url.urlSrc}" width="300px" height="300px">
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer" />
<script type="text/javascript">
    var prefix = ctx + "product/manager";

    $("#form-manager-edit").validate({
        onkeyup: false,
        rules:{
            managerNum:{
                remote: {
                    url: prefix + "/checkManagerNumUnique",
                    type: "post",
                    dataType: "json",
                    data: {
                        "managerNum" : function () {
                            return $.common.trim($("#managerNum").val())
                        }
                    },
                    dataFilter: function(data, type) {
                        return $.validate.unique(data);
                    }
                }
            },
            typeSort:{
                digits:true
            },
        },
        messages: {
            "managerNum": {
                remote: "产品管理型号已经存在"
            }
        },
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            $.operate.save(prefix + "/edit", $('#form-manager-edit').serialize());
        }
    }


    function imagesNodeId(obj) {
        $.ajax({
            url: prefix + "/changeImagesUrl",
            data:{urlId:obj.value},
            dataType:"json",
            type:"post",
            async:"true",
            success:function (data) {
                if(data.code == 0){
                    $("#urlSrcId").attr("src",data.data.urlSrc);
                    // $("#imagesDivId").append("<img src=\""+data.data.urlSrc+"\" width=\"300px\" height=\"300px\">")
                }else {
                    console.log(data.msg);
                }
            }
        });
    }
</script>
</body>
</html>
